package com.licode.codekit.utils;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.extensions.PluginId;

import java.io.File;
import java.nio.file.Path;

public class PluginUtil {
    public static String getPluginDir() {
        String pluginDir = "";
        Path pluginPath = null;
        PluginId pluginId = PluginId.getId("com.licode.codekit");
        IdeaPluginDescriptor plugin = PluginManager.getInstance().findEnabledPlugin(pluginId);
        if (null != plugin) {
            pluginPath = plugin.getPluginPath();
        }

        if (null != pluginPath) {
            File file = pluginPath.toFile();
            pluginDir = file.getAbsolutePath();
            if (file.isFile()) {
                pluginDir = StrUtil.getFileDir(pluginDir);
            }
        }

        return pluginDir;
    }
}
